<template>
  <div className="app-container">
    <div className="table-container">
      <base-list
        ref="table"
        url="/book_recommend"
        :options="options"
        :columns="columns"
        :format="format"
        :rules="rules"
        permission="ADMIN"
        @reloadOptions="handleGetOptions"
      />
    </div>
  </div>
</template>

<script>
import {getBaseList, getBaseOptions} from '@/api/common'
import BaseList from '@/components/BaseList/index.vue'

export default {
  name: 'BookExpand',
  components: {BaseList},
  data() {
    return {
      columns: [
        {show: true, edit: true, width: 'auto',minWidth: '300', key: 'title', label: '标题', tooltip: '标题', type: 'WORD', queryable: true, sortable: true},
        {show: true, edit: true, width: 'auto',minWidth: '100', key: 'image', label: '主图', tooltip: '主图', type: 'IMAGE',imageSuffix: 'recommend-'},
        {show: true, edit: true, width: 'auto',minWidth: '300', key: 'books', label: '图书', tooltip: '图书', searchType: 'WORD', type: 'REMOTE_SELECT_BOOK', remote: {multiple: true}, queryable: true},
        {show: false, edit: false, width: 'auto',minWidth: '200', key: 'createTime', label: '创建时间', tooltip: '创建时间', type: 'DATE_TIME'},
        {show: true, edit: false, width: 'auto',minWidth: '200', key: 'updateTime', label: '更新时间', tooltip: '更新时间', type: 'DATE_TIME', queryable: true},
        {show: false, edit: false, width: 'auto',minWidth: '200', key: 'createUser', label: '创建人', tooltip: '创建人', type: 'WORD'},
        {show: false, edit: false, width: 'auto',minWidth: '200', key: 'updateUser', label: '修改人', tooltip: '修改人', type: 'WORD'},
      ],
      format: {
        books: (data, index) => {
          return (data.books || []).map(e => e.name + '(' + e.id + ')').join(',')
        },
        createUser: (data, index) => {
          return data.createUser ? data.createUser.nickName + '('+data.createUser.id+')' : ''
        },
        updateUser: (data, index) => {
          return data.updateUser ? data.updateUser.nickName + '('+data.updateUser.id+')' : ''
        }
      },
      rules: {
        add: {
          title: [{required: true, message: '标题必填!', trigger: 'blur'}],
          image: [{required: true, message: '主图必填!', trigger: 'change'}],

        },
        edit: {
          id: [{required: true, message: '请选择数据!', trigger: 'change'}],
          title: [{required: true, message: '标题必填!', trigger: 'blur'}],
          image: [{required: true, message: '主图必填!', trigger: 'change'}],
        }
      },
      options: {
      }
    }
  },

  created() {
    this.handleGetOptions()
  },
  mounted() {
  },
  methods: {
    handleGetOptions() {
      const options = JSON.parse(localStorage.getItem('allOptions'))
      if (options) {
        this.options = Object.assign(this.options, options)
      }
    }
  }
}
</script>


